/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package business;

import business.services.ComparatorFactory;
import java.io.Serializable;
import java.util.List;
import java.util.SortedMap;
import model.Project;
import model.ScheduleBaseline;
import org.apache.commons.logging.Log;
import persistence.PersistFactory;
import persistence.services.PersistenceException;
import utils.SmLogFactory;

/**
 *
 * @author jmoura
 * http://www.postgresql.org/docs/devel/static/datatype-enum.html;
 *
 */
public class ProjectFacade extends BaseFacade implements Serializable {

    private static final Log log = SmLogFactory.getLog(ProjectFacade.class);

    public List<Project> getProjectList(boolean onlyActive) {
        if (onlyActive) {
            try {
                return PersistFactory.getProjectDao().list();
            } catch (PersistenceException ex) {
                log.fatal(ex);
                throw new UnsupportedOperationException("Full Stop!");
            }
        } else {
            throw new UnsupportedOperationException("Not yet implemented");
        }
    }

    public void sortByName(List<Project> projectList) {
        ComparatorFactory.getComparatorProjectSorterByName(projectList);
    }

    /**
     * list all capital,non-cap and labor costs associated with project.
     *
     * @param project
     * @return
     */
    public int getCostTotal(Project project) {
        //TODO: implement the total cost routine. 
        return (int) Math.random();
    }

    /**
     * list all baselines
     * @param project
     * @return 
     */
    public SortedMap<Integer, ScheduleBaseline> getScheduleBaselines(Project project) {
        return project.getScheduleBaselines();
    }
}
